<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
<script type="text/javascript" src="../Ryanjs/login/style.js"></script>
        <link href="../Ryancss/login_public.css" rel="stylesheet" type="text/css"/>
        <link href="../Ryancss/login_style.css" rel="stylesheet" type="text/css"/>

</head>
<style>


 .aui-btn-default {
    float: right;
    position: absolute;
    right: 0px;
    top: 39px;
    z-index: 10002;
    color: #ffffff;
    background: none;
    border: none;
    margin-top: -35px;
    width: 100px;
    height: 40px;
}

</style>
<body>
<div class="main_login">
    <div class="tit">
        <span  tapmode onclick="openWin('login')" >登录</span>
        <span class="sp2  "   tapmode onclick="openWin('reg_frm')"  >注册</span>
        <div class="clear"></div>
    </div>
    <div class="main_box">

        <div class="box_con box_reg">
                <div class="con_bg">
                    <span class="first_sp"><input  id="username" type="tel"  minlength="11" maxlength="11" placeholder="输入手机号码" ></span>
                     <span class="first_sp" style="display :none;" id="display-block-dxyz"> <input id="yzcode" type="text" autocomplete="off" placeholder="短信验证码" />
					<input id="btn1" type="button"  value="获取验证码" onclick="getCode()" />	</span>						
                    <span class="second_sp thrid_sp"><input  id="password" type="password" placeholder="请输入新密码"/></span>
                  <!--  <span class="second_sp thrid_sp"><input id="share" type="text"  minlength="6" maxlength="6" placeholder="邀请码(选填)"/></span>   -->
                </div>
                <a  onclick="toReg()" class="log_btn reg_btn">重置密码</a> 
   
        </div>
    </div>
	
	
    <div class="footer_pic">        
<!--	
		<img  onclick="WX_login()" src="" alt="微信" class="pic2"/>
-->
        <img src="" class="pic1"/>
  </div>
</div>


</body>

<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript">
    var api_url = localStorage.getItem('api_url');
    var onoff = true;
    var code_data = '';
    apiready = function () {
      api.parseTapmode();
      var header = $api.byId('aui-header');
      $api.fixStatusBar(header);
      var headerPos = $api.offset(header);
      var body_h = $api.offset($api.dom('body')).h;

    }
	
    if(localStorage.getItem('dxzce') == '0'){

    }else{

        var obj = document.getElementById("display-block-dxyz");
        obj.setAttribute("style", "display :block;");


    }	
	
	
    function closeWin(){
        api.closeWin({
        });
    }


    function toReg(){
      var password = $api.val($api.byId('password'));
      var username = $api.val($api.byId('username'));
      var yzcode = $api.val($api.byId('yzcode'));
      var user_id = localStorage.getItem('user_id');
      var lao_pswd = localStorage.getItem('password');
      if(username == ''){
	  

		
						api.toast({
							msg: '请输入账号',
							duration: 5000,
							location : 'middle' 
						});
		
        return;
      }
      if(localStorage.getItem('dxzce') == '1'){
			if (yzcode == '') {
				api.alert({
					title: '警告！~',
					msg: '请输入验证码',
				});
				return;
			}	  
			var moduleSMSSDK = api.require('smssdk');
			var param = {
				zone: '86',
				phoneNumber: username,
				code: yzcode
			};
    moduleSMSSDK.commitCode(param, function(ret, err) {	
	if (err !== null && err !== undefined && err !== '') {
					// 错误消息示例：{"msg":"Template not exist.","code":484}
					alert("Error:\n" + JSON.stringify(err));
					return;
				}

	});	
	  
	  
	  }
      if(password == ''){

		
							api.toast({
							msg: '请输入密码',
							duration: 5000,
							location : 'middle' 
						});	
				
        return;
      }
      if(username.length != 11){

							api.toast({
							msg: '请输入11位手机号码',
							duration: 5000,
							location : 'middle' 
						});			
		
		
        return;
      }
      if(username.length < 6){
	  
							api.toast({
							msg: '请输入6位以上密码',
							duration: 5000,
							location : 'middle' 
						});			
			  

        return;
      }
  /*    if (yzcode != code_data) {
	  
	  
							api.toast({
							msg: '短信验证码不正确',
							duration: 5000
						});			
		
        return;

      }  */
      api.ajax({
          url: api_url+'/login/login/repass.html',
          method: 'get',
          data: {
              values: {
                  username:username,
                  password:password,
                  key: 'p2piunink'
              }
          }
      },function(ret, err){
          if (ret) {
		  
				if (ret.code == 0) {
	  
							api.toast({
							msg: ret.msg,
							duration: 5000,
							location : 'middle' 
						});			
			  	  			  
			  
			  }else if(ret.code == 1)  {
                localStorage.setItem('password',password);
				
				
				
	        api.alert({
            title: '修改成功',
            msg: '请重新登录！',
        });
						/*	api.toast({
							msg: '修改成功 请重新登录！',
							duration: 5000
						});		

*/


                api.sendEvent({
                  name: 'outLogin',
                  extra: {
                  }
                });

               api.closeWin();
              }
          } else {

			
							api.toast({
							msg: '网络错误！',
							duration: 5000,
							location : 'middle' 
						});			
			  	  			  				
			
          }
      });
 
	}

    function openLogin(name,password){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam:{name:name,password:password},
        });
    }

    //获取验证码
    function getCode1(){
      var yzcode = $api.val($api.byId('yzcode'));

      var username = $api.val($api.byId('username'));
      if (!onoff) {
        return;
      }
      onoff = false;

      if(username == ''){
        api.alert({
            title: '警告！~',
            msg: '请输入手机号码',
        });
        onoff = true;
        return;
      }
      if(username.length != 11){
        api.alert({
            title: '警告！~',
            msg: '请输入11位手机号码',
        });
        onoff = true;
        return;
      }
      code_data = RndNum(6);
      var content = escape('#code#='+code_data);
      //alert(content);
      api.ajax({
          url: api_url+'/login/login/yzcode.html',
          method: 'get',
          data: {
              values: {
                  username: username,
                  key: code_data
              }
          }
      },function(ret, err){
        if (ret.code==0) {
          onoff = true;
          api.alert({
              title: '提示',
              msg: ret.msg,
          });
          return;
        }else {
          onoff = true;
          getApicode(username,content);
        }
      });

    }
    //生成验证码
    function RndNum(n){
      var rnd="";
      for(var i=0;i<n;i++)
          rnd+=Math.floor(Math.random()*10);
      return rnd;
    }

    function getApicode(username,content) {
      var btn1 = $api.byId('btn1');
      api.ajax({
          url: 'http://v.juhe.cn/sms/send?mobile='+username+'&tpl_id=103638&tpl_value='+content+'&key=bd5031f27476d9495207b3aa65b06b7d',
          method: 'get'
      },function(ret, err){
              api.toast({
                  msg: '发送成功',
                  duration: 1000,
                  location: 'middle'
              });
              var nuw = 120;
              var timer = setInterval(function(){
                nuw --;

                if (nuw < 1) {
                  btn1.innerHTML = '获取';
                  clearInterval(timer);
                  onoff = true;
                }else {
                  btn1.innerHTML = nuw+'s';
                }


              },1000)
      });
    }


	//获取验证码
		function getCode() {
			var yzcode = $api.val($api.byId('yzcode'));
			var btn1 = $api.byId('btn1');
			var username = $api.val($api.byId('username'));
			localStorage.setItem('reg_name', username);
			if (!onoff) {
				return;
			}
			onoff = false;

			if (username == '') {
				api.alert({
					title: '警告！',
					msg: '请输入手机号码',
				});
				onoff = true;
				return;
			}
			if (username.length != 11) {
				api.alert({
					title: '警告！',
					msg: '请输入11位手机号码',
				});
				onoff = true;
				return;
			}
			var moduleSMSSDK = api.require('smssdk');
			var param = {
				zone: '86',
				phoneNumber: username,
				tempCode: ''
			};
			moduleSMSSDK.getTextCode(param, function(ret, err) {
				if (err !== null && err !== undefined && err !== '') {
					// 错误消息示例：{"msg":"Template not exist.","code":484}
					alert("Error:\n" + JSON.stringify(err));
				} else {
					// 正常消息示例：{"smart":false}
					api.toast({
						msg: '发送成功',
						duration: 1000,
						location: 'middle'
					});
					var nuw = 60;
					var timer = setInterval(function() {
						nuw--;
						if (nuw < 1) {
							btn1.value = "获取验证码";
							clearInterval(timer);
							onoff = true;
						} else {
							btn1.value = nuw + 's';
						}
					}, 1000)
				}
			});


		}


    function openWin(name){
          var delay = 0;
          if(api.systemType != 'ios'){
              delay = 300;
          }
          api.openWin({
              name: ''+name+'',
              url: ''+name+'.html',
              bounces:false,
              delay: delay,
              slidBackEnabled:true,
              vScrollBarEnabled:false
          });
      }
</script>
</html>
